#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    int fd = open("test.txt", O_RDWR | O_CREAT, 0666);
    if (fd == -1) {
        perror("open failed");
        exit(1);
    }
    int fd_flags = fcntl(fd, F_GETFD);
    printf("Original FD flags: %d\n", fd_flags);
    if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
        perror("fcntl F_SETFD failed");
        exit(1);
    }
    execl("/bin/ls", "ls", "-l", NULL);
    perror("execl failed");
    return 1;
}
